#include<bits/stdc++.h>
using namespace std;
struct role{
	int health;
	int attack;
};
struct player{
	int hero;
	role summon[7];
};
player a,b;
void init(player &x){
	x.hero = 30;
	for(int i = 0; i < 7; i++){
		x.summon[i].health = 0;
		x.summon[i].attack = 0;
	}	
}
void su(player &ing){
	int pos, at, he;
	cin >> pos >> at >> he;
	for(int j = 5; j >= pos - 1; j--){
		ing.summon[j + 1] = ing.summon[j];
	}
	ing.summon[pos - 1].attack = at;
	ing.summon[pos - 1].health = he;
	//cout << b.summon[pos - 1].attack << "  " <<b.summon[pos - 1].health<< endl;	
}
void attac(player &ing, player &ed){
	int att,def;
	cin >> att >> def; 
	if(def == 0){
		ed.hero -= ing.summon[att -1].attack;
		//if(ed.hero < 0)
		  //  ed.hero = 0;
	}
	else{
		ed.summon[def-1].health -= ing.summon[att-1].attack;
	//	cout << def-1 << "  " << ed.summon[def-1].health << endl;
		ing.summon[att-1].health -= ed.summon[def-1].attack;
	//	cout << att-1 << "  " << ing.summon[att-1].health << endl;
		if(ed.summon[def-1].health<=0){
			for(int j = def-1; j < 6;j ++){
				ed.summon[j] = ed.summon[j + 1];
			} 
			ed.summon[6].health = 0;
			ed.summon[6].attack = 0;
		}
		if(ing.summon[att-1].health<=0){
			for(int j = att-1; j < 6;j ++){
				ing.summon[j] = ing.summon[j + 1];
			} 
			ing.summon[6].health = 0;
			ing.summon[6].attack = 0;
		}	
	}	
}
int main(){
	init(a);
	init(b);
	int n;
	cin >> n;
	player ing = a;
//	cout << ing.hero << endl;
    bool mark = 0;
	for(int i = 0; i < n; i++){
		string action;
		cin >> action;
		if(action[0] == 'e'){
			mark = !mark;
		}else if(action[0] == 's'){  
			if(mark == 1){
				su(b);
			}else{
				su(a);
			}	
		}else {
			if(mark == 1){
				attac(b,a);
			}else{
				attac(a,b);
			}
		}
	}
	if(a.hero <= 0 && b.hero > 0)
		cout << "-1" << endl;
	else if(b.hero <= 0 && a.hero >0)
		cout << "1" << endl;
	else
		cout << "0" << endl;
	cout << a.hero << endl;
	int p = 0;
	for(int i = 0; a.summon[i].health > 0;i++){
		p++;
	}
	cout << p ;
	if(p)
		cout << " ";
	else 
		cout << endl;
	for(int i = 0; i < p - 1;i++){
		cout << a.summon[i].health << " ";
	}
	if(p)
		cout << a.summon[p-1].health << endl;
	cout << b.hero << endl;
	p = 0;
	for(int i = 0; b.summon[i].health > 0;i++){
		p++;
	}
	cout << p ;
	if(p)
		cout << " ";
	else 
		cout << endl;
	for(int i = 0; i < p - 1;i++){
		cout << b.summon[i].health << " ";
	}
	if(p)
		cout << b.summon[p-1].health << endl;
	return 0;
}
